<template>
  <view class="index">
    <view class="submit-age">
      <nut-form>
        <nut-form-item label="请填写年龄：">
          <nut-input-number v-model="age" min="5" max="70" decimal-places="1" button-size="large" input-width="100px" @change="ageChange"/>
        </nut-form-item>
      </nut-form>
    </view>
    <view>
      <nut-button class="submit-btn" type="success" size="large" @click="submit" :disabled="submitDisabled">提交</nut-button>
    </view>
  </view>
</template>

<script>
import './submit.less'
import Taro from '@tarojs/taro'

export default {
  data() {
    return {
      params: {},
      age: 0,
      submitDisabled: true,
    }
  },
  methods: {
    setParams() {
      this.params = Taro.getCurrentInstance().router.params
    },
    ageChange(e) {
      if (this.age < 5 || this.age > 70) {
        return
      }
      this.submitDisabled = false
    },
    submit() {
      if (this.age < 5 || this.age > 70) {
        Taro.showToast({
          title: '请输入正确的年龄(5~70岁之间)',
          icon: 'none'
        })
        return
      }
      Taro.navigateTo({
        url: '/pages/result/result?score=' + this.params.score + '&age=' + this.age
      })
    },
  },
  mounted() {
    this.setParams()
  }
}
</script>
